﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections;

namespace HostsOperate.Test
{
    class Program
    {
        static void Main(string[] args)
        {

            // HostsHelper _helper = new HostsHelper();

            //Console.WriteLine(_helper.HostDatas.Count);
            //_helper.Add(new HostData(true,"192.168.1.126","text.weilanliuxue.cn"));

            //Console.WriteLine(_helper.HostDatas.Count);

            //string _FileName = @"C:\Windows\System32\drivers\etc\hosts";
            //StreamWriter writer = new StreamWriter(_FileName);
            //writer.Write("1234");
            //writer.Close();


            // TestDriveInfo();
            //TestSystemDrive();
            TestSystemDrive2();

            Console.Read();
        }

        static void TestSystemDrive2()
        {
            ////获取当前系统磁盘符方法1，返回：C:
            //string path = Environment.GetEnvironmentVariable("systemdrive");
            ////获取当前系统磁盘符方法2,返回：C:
            //string path = Environment.ExpandEnvironmentVariables("%systemdrive%");
            //Console.WriteLine(path);
            ////获取当前系统目录
            //Console.WriteLine("GetFolderPath: {0}",Environment.GetFolderPath(Environment.SpecialFolder.System));
            ////获取当前系统桌面
            //Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System));
        }
        /// <summary>
        /// 获取当前系统盘，信息
        /// </summary>
        static void TestSystemDrive()
        {


            //--------------获取当前程序信息
            //当前程序启动的命令，字符串
            Console.WriteLine("CommandLine:{0}", Environment.CommandLine);
            string[] arguments = Environment.GetCommandLineArgs();
            Console.WriteLine("GetCommandLineArgs:{0}", string.Join(", ", arguments));
            //获取当前程序目录
            Console.WriteLine("CurrentDirectory:{0}", Environment.CurrentDirectory);
            //获取当前程序，工作的物理内存大小
            Console.WriteLine("WorkingSet: {0}", Environment.WorkingSet);
            //退出码
            Console.WriteLine("ExitCode:{0}", Environment.ExitCode);
            //获取当前程序是否开机启动
            Console.WriteLine("HasShutdownStarted: {0}", Environment.HasShutdownStarted);
            //获取当前跟踪信息
            Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace);
            //获取换行符
            Console.WriteLine("NewLine: {0}  first line{0}  second line{0}  third line",
                            Environment.NewLine);

            //--------------获取当前用户信息
            //当前用户的域名称
            Console.WriteLine("UserDomainName: {0}", Environment.UserDomainName);
            //当前用户是否交互
            Console.WriteLine("UserInteractive: {0}", Environment.UserInteractive);
            //当前用户名称
            Console.WriteLine("UserName: {0}", Environment.UserName);

            //--------------获取当前系统信息
            //获取当前计算机名称
            Console.WriteLine("MachineName: {0}", Environment.MachineName);
            //获取系统镜像等版本
            Console.WriteLine("Version: {0}", Environment.Version.ToString());
            //获取当前操作系统版本
            Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());
            //获取当前系统目录
            Console.WriteLine("GetFolderPath: {0}",
                            Environment.GetFolderPath(Environment.SpecialFolder.System));
            //获取当前计算机逻辑磁盘名称列表
            String[] drives = Environment.GetLogicalDrives();
            Console.WriteLine("GetLogicalDrives: {0}", String.Join(", ", drives));
            //获取系统目录
            String str;
            String nl = Environment.NewLine;
            String query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
            str = Environment.ExpandEnvironmentVariables(query);
            Console.WriteLine("ExpandEnvironmentVariables: {0}  {1}", nl, str);
            //获取系统临时文件夹
            Console.WriteLine("GetEnvironmentVariable: {0}  My temporary directory is {1}.", nl,
                                    Environment.GetEnvironmentVariable("TEMP"));

            //--------------遍历所有信息
            Console.WriteLine("GetEnvironmentVariables: ");
            IDictionary environmentVariables = Environment.GetEnvironmentVariables();
            foreach (DictionaryEntry de in environmentVariables)
            {
                Console.WriteLine("  {0} = {1}", de.Key, de.Value);
            }
        }
        /// <summary>
        /// 测试磁盘信息
        /// </summary>
        static void TestDriveInfo()
        {
            DriveInfo[] allDirves = DriveInfo.GetDrives();
            //检索计算机上的所有逻辑驱动器名称
            foreach (DriveInfo item in allDirves)
            {
                //Fixed 硬盘
                //Removable 可移动存储设备，如软盘驱动器或USB闪存驱动器。
                Console.Write(item.Name + "---" + item.DriveType);
                if (item.IsReady)
                {
                    Console.Write(",容量：" + item.TotalSize + "，可用空间大小：" + item.TotalFreeSpace);
                }
                else
                {
                    Console.Write("没有就绪");
                }
                Console.WriteLine();
            }
        }
    }
}
